// 设备检测工具
export const isMobile = (): boolean => {
  if (typeof window === 'undefined') return false;
  
  // 检查屏幕宽度
  const screenWidth = window.innerWidth;
  if (screenWidth < 640) return true; // Tailwind sm breakpoint
  
  // 检查用户代理
  const userAgent = navigator.userAgent.toLowerCase();
  const mobileKeywords = [
    'mobile', 'android', 'iphone', 'ipad', 'ipod', 
    'blackberry', 'windows phone', 'opera mini'
  ];
  
  return mobileKeywords.some(keyword => userAgent.includes(keyword));
};

export const isPC = (): boolean => {
  return !isMobile();
};

// React Hook for device detection
import { useState, useEffect } from 'react';

export const useDeviceType = () => {
  const [deviceType, setDeviceType] = useState<'mobile' | 'pc'>(() => {
    if (typeof window === 'undefined') return 'pc';
    return isMobile() ? 'mobile' : 'pc';
  });

  useEffect(() => {
    const handleResize = () => {
      setDeviceType(isMobile() ? 'mobile' : 'pc');
    };

    window.addEventListener('resize', handleResize);
    return () => window.removeEventListener('resize', handleResize);
  }, []);

  return deviceType;
};